package com.topisv.tms.repository;

import java.util.List;

import org.springframework.data.jpa.repository.JpaSpecificationExecutor;
import org.springframework.data.jpa.repository.Modifying;
import org.springframework.data.jpa.repository.Query;
import org.springframework.data.repository.PagingAndSortingRepository;

import com.topisv.tms.entity.CustomerAreaGroup;

public interface CustomerAreaGroupDao extends JpaSpecificationExecutor<CustomerAreaGroup>,PagingAndSortingRepository<CustomerAreaGroup, Long> {

	List<CustomerAreaGroup> findByCustomerCode(String customerCode);
	
	List<CustomerAreaGroup> findByCustomerCodeOrderByLevelAsc(String customerCode);
	
	CustomerAreaGroup findByCustomerCodeAndAreaGroupCode(String customerCode,String areaGroupCode);
	
	@Modifying
	@Query("delete from CustomerAreaGroup where customerCode=?1")
	void deleteCustomerCode(String customerCode);
	
	@Modifying
	@Query("UPDATE CustomerAreaGroup SET level=?1 WHERE customerCode=?2 AND areaGroupCode =?3")
	void updateLevelByCustomerAndWarehouse(String level, String customerCode, String areaGroupCode);
}
